Skip to content

Conversation

@alajv76-hub
Copy link

import requests from typing import Dict

PINTEREST_ACCESS_TOKEN = os.getenv("PINTEREST_ACCESS_TOKEN") PINTEREST_BOARD_ID = os.getenv("PINTEREST_BOARD_ID")

PINTEREST_PINS_URL = "https://api.pinterest.com/v5/pins"

def create_pin(image_url: str, title: str, description: str, alt_text: str) -> Dict:
"""
Create a Pinterest pin using the v5 API.
"""

if not PINTEREST_ACCESS_TOKEN:
    raise RuntimeError("PINTEREST_ACCESS_TOKEN environment variable is not set")

if not PINTEREST_BOARD_ID:
    raise RuntimeError("PINTEREST_BOARD_ID environment variable is not set")

headers = {
    "Authorization": f"Bearer {PINTEREST_ACCESS_TOKEN}",
    "Content-Type": "application/json"
}

payload = {
    "board_id": PINTEREST_BOARD_ID,
    "title": title[:100],
    "description": description[:500],
    "alt_text": alt_text[:500],
    "media_source": {
        "source_type": "image_url",
        "url": image_url
    }
}

response = requests.post(
    PINTEREST_PINS_URL,
    headers=headers,
    json=payload,
    timeout=30
)

response.raise_for_status()
return response.json()

At the moment we are not accepting contributions to the repository.

    parser = argparse.ArgumentParser(description="Download from Pexels and post to Pinterest")
    parser.add_argument("--query", required=True, help="Search query for Pexels")
    parser.add_argument("--count", type=int, default=1, help="Number of items to fetch")
    parser.add_argument("--use-hosting", action="store_true")
    parser.add_argument("--include-attribution", action="store_true")
    args = parser.parse_args()

    photos = search_pexels(args.query, args.count)

    if not photos:
        print("No photos found.")
        sys.exit(1)

    for photo in photos:
        image_url = photo["src"]["original"]
        photographer = photo.get("photographer", "Unknown")
        pexels_link = photo.get("url", "")

        final_image_url = image_url

        if args.use_hosting:
            filename = f"temp_{int(time.time())}.jpg"
            download_file(image_url, filename)
            final_image_url = upload_to_imgur(filename)
            os.remove(filename)

        description = f"Photo about {args.query}"
        if args.include_attribution:
            description += f"\n📸 {photographer} via Pexels\n{pexels_link}"

        response = create_pin(
            image_url=final_image_url,
            title=f"{args.query.title()} Inspiration",
            description=description,
            alt_text=f"{args.query} image"
        )

        print("✅ Pin created:", response.get("id"))
        time.sleep(2)
import requests
from typing import Dict

PINTEREST_ACCESS_TOKEN = os.getenv("PINTEREST_ACCESS_TOKEN")
PINTEREST_BOARD_ID = os.getenv("PINTEREST_BOARD_ID")

PINTEREST_PINS_URL = "https://api.pinterest.com/v5/pins"

def create_pin(image_url: str, title: str, description: str, alt_text: str) -> Dict:
    """
    Create a Pinterest pin using the v5 API.
    """

    if not PINTEREST_ACCESS_TOKEN:
        raise RuntimeError("PINTEREST_ACCESS_TOKEN environment variable is not set")

    if not PINTEREST_BOARD_ID:
        raise RuntimeError("PINTEREST_BOARD_ID environment variable is not set")

    headers = {
        "Authorization": f"Bearer {PINTEREST_ACCESS_TOKEN}",
        "Content-Type": "application/json"
    }

    payload = {
        "board_id": PINTEREST_BOARD_ID,
        "title": title[:100],
        "description": description[:500],
        "alt_text": alt_text[:500],
        "media_source": {
            "source_type": "image_url",
            "url": image_url
        }
    }

    response = requests.post(
        PINTEREST_PINS_URL,
        headers=headers,
        json=payload,
        timeout=30
    )

    response.raise_for_status()
    return response.json()
@github-actions
Copy link

At the moment we are not accepting contributions to the repository.

Feedback for Copilot.vim can be given in the feedback forum.

@github-actions github-actions bot closed this Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant